<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="/WEB-INF/taglib.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>组织机构</title>
    <%@ include file="/WEB-INF/jsp/include.jsp" %>
    <script type="text/javascript">
        var params = new Object();
        $(function () {
            setAjaxLoading();
            ajaxJson('${path}/basicinfo/taxPayersInfo/getDirectChildrenTreeData', params, singleInitTree);
        });

        //初始化树点击函数
        function zTreeOnClick(event, treeId, treeNode) {
            params.pid = treeNode.id;
            if (!treeNode.pIds) {
                treeNode.pIds = "";
            }
            params.pidSet = treeNode.pIds;
        };
        //       展开树调用方法
        function zTreeOnExpand(event, treeId, treeNode) {
            params.orgCode = treeNode.code;
            treeSingleLoad(params, treeId, treeNode)
        };
        //     树层级加载方法
        function treeSingleLoad(params, treeId, treeNode) {
            var treeObj = $.fn.zTree.getZTreeObj("tree");
            var node = treeNode;
            //没有子节点才去查询
            if (node.children == null || node.children == "undefined") {
                $.ajax({
                    type: "POST",
                    async: true,
                    url: "${path}/basicinfo/taxPayersInfo/getDirectChildrenTreeData",
                    data: params,
                    dataType: "json",
                    success: function (data) {
                        var analyMsg = data;
                        analyMsg.code == "0000"
                        if (analyMsg.code == "0000") {
                            //添加新节点
                            var newNode = treeObj.addNodes(node, data.returnObject);
                        }
                    },
                    error: function (event, XMLHttpRequest, ajaxOptions, thrownError) {
                        $.alert("default", "error", data.responseText);
                    }
                });
            }
        }

        function dataFilter(treeId, parentNode, responseData) {
            var rows = [];
            if (responseData) {
                if (responseData.code != '0000') {
                    $.messager.alert('操作提示', responseData.msg, 'info', function () {
                    });
                } else {
                    rows = responseData.returnObject;
                }
            }
            return rows;
        };

        function btnOk() {
            var treeObj = $.fn.zTree.getZTreeObj("tree");
            var nodes = treeObj.getSelectedNodes();
            if (nodes != null && nodes.length > 0) {
                var treeNode = nodes[0];
                //返回选中的组织名称
                var returnValue = new Object();
                returnValue.relaOrgid = treeNode.id;
                returnValue.relaOrgname = treeNode.name;
                parent.window.callback_selectOrg(returnValue);
                setTimeout("closeLayer()", 100);
            } else {
                $.messager.alert('操作提示', '请选择一个组织机构！', 'info', function () {

                });
            }
        }
    </script>
</head>

<body class="easyui-layout">
<%@ include file="/WEB-INF/jsp/loading.jsp" %>
<div region="center" style="padding: 5px;" border="false">
    <div class="easyui-layout" fit="true" border="false">
        <div region="center" title="主体部分" border="false" noheader="true" style="padding: 0px;">
            <div class="easyui-layout" fit="true" border="false">
                <div data-options="region:'center',title:'',split:false,border: false">
                    <div region="center" title="组织机构树" border="false">
                        <div>
                            <ul id="tree" class="ztree" style="width: 90%; height: 90%;"></ul>
                        </div>
                    </div>
                </div>
                <div data-options="region:'south',title:'',split:false,border: false" style="width:100px;">
                    <div align="center" style="margin-top: 15px;">
                        <a id="btn_ok_d" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok"
                           onclick="btnOk()">确定</a>
                        <a id="btn_close_d" href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel"
                           onclick="closeLayer();">关闭</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
